/***************************************************************************
                          CountryView.cpp  -  description
                             -------------------
    begin                : October 29 2009
    copyright            : Copyright 2009, ACKERMANN Thibaut
    email                : tackerma@edu.univ-fcomte.fr
    website              : http://code.google.com/p/nover-project/
    license              : GNU GPL v3
 ***************************************************************************/
/* *************************************************************************
 *  This file is part of NOver-Project.
 *  
 *  NOver-Project is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *  
 *  NOver-Project is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with NOver-Project.  If not, see <http://www.gnu.org/licenses/>.
 * *************************************************************************/


#include "CountryView.hpp"


CountryView::CountryView(std::string name) throw (MyException)
{
	gui = StateMgr::Instance()->getGuiEnv();
	driver = StateMgr::Instance()->getDriver();
	winheight = StateMgr::Instance()->getWindowHeight();
	winwidth = StateMgr::Instance()->getWindowWidth();
	
	country = DataMgr::Instance()->getCountryByName(name);
	
	if(!country)
		throw MyException("Erreur, le pays n'a pas été chargé par le DataManager", __FILE__, __LINE__);
	
	zoomMap = new Zoomable(0, id_CountryZoomable, core::rect<s32>(0, 0, winwidth-150, winheight));
	zoomMap->setImage(driver->getTexture(Path(MediaPath).a("Continents").a("Countries").a(country->map).genc()));
	gui->getRootGUIElement()->addChild(zoomMap);
	
	btnRetour = gui->addButton(core::rect<s32>(winwidth-130, 20, winwidth-50, 40), 0, id_CountryBackButton, L"Retour", L"Retour au continent");
	
}


CountryView::~CountryView()
{
	delete zoomMap;
}


void CountryView::frame(float time)
{
	// barre de séparation
	StateMgr::Instance()->getDriver()->draw2DLine(position2d<s32>(winwidth-150, 0), position2d<s32>(winwidth-150, winheight), SColor(255, 0, 0, 0));
}


void CountryView::resize(int width, int height)
{
	// 150 de marge a droite, pour le menu
	zoomMap->setAbsolute(rect<int>(0, 0, width-150, height));
	
	btnRetour->setRelativePosition(position2d<int>(width-130, 20));
	
	winheight = height;
	winwidth = width;
}


